<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Sanatorium;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SanatoriumController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {

        return Grid::make(new Sanatorium(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('sanatorium_name');
            $grid->column('contacts');
            $grid->column('mobile');
            $grid->column('seriver_time');
            $grid->column('address');
            $grid->column('serivce');
            $grid->column('imgs')->image();
            $grid->column('type')->using([1=> '颐康中心', 2 => '养老机构']);
            $grid->column('longitude');
            $grid->column('latitude');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Sanatorium(), function (Show $show) {
            $show->field('id');
            $show->field('sanatorium_name');
            $show->field('contacts');
            $show->field('mobile');
            $show->field('seriver_time');
            $show->field('address');
            $show->field('serivce');
            $show->field('imgs');
            $show->field('type');
            $show->field('longitude');
            $show->field('latitude');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Sanatorium(), function (Form $form) {
            $form->display('id');
            $form->text('sanatorium_name');
            $form->text('contacts');
            $form->text('mobile');
            $form->datetime('seriver_time');
            $form->text('address');
            $form->text('serivce');
            $form->file('imgs')->disk('admin');
            $form->select('type')->options([1=>'颐康中心',2=>'养老机构']);
            $form->text('longitude');
            $form->text('latitude');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
